<style>
.formula{
padding:0 0 0 0;
margin:0 0 0 0;
}
.formula tbody tr{
padding:0 0 0 0;
margin:0 0 0 0;
}
.formula tbody tr td{
padding:0 0 0 0;
margin:0 0 0 0;
text-align:center;
width:90px;
height:30px;
line-height:20px;
}
.formula tbody tr td div{
width:150px;
}
.formula tbody tr td.cell_cancel{
width:110px;
text-align:left;
padding-left:9px;
}
</style>
<div class="pageContent">
	
	<form method="post" action="/index.php?act=formula&st=table_save" class="pageForm required-validate" onsubmit="return validateCallback(this, dialogAjaxDone)">
		<input type="hidden" name="parent_id" value="{$parent_id}">
		<div class="pageFormContent" layoutH="58">

				<center>
					<table border="1" class="formula">		
						<tbody>
							
							{foreach item=items key=key from=$formula_table.basic_price}
							<tr width="80%">
								{foreach item=item key=ke from=$items}
									{if is_array($item)}
										{foreach item=ite key=k from=$item}
											{if $ke eq 0}
												<td><div>{$ite}</div></td>
											{else}
												<td>{$ite}</td>
											{/if}
										{/foreach}
									{else}
										{if $ke eq 0}
											<td><div>{$item}</div></td>
										{else}
											<td><div>{$item}</div></td>
										{/if}
									{/if}
								{/foreach}
							</tr>
							{/foreach}
							
							{foreach item=items key=key from=$formula_table.price_list}
							<tr width="80%">
								<td rowspan="{$items.count}" colspan="1" class="fomula_table_{$key}" depth="1" tdid="{$items.id}" arrcount="0">
								<div>
									<!--{if !$items.childs}
										<a href="javascript:void(0)" class="btnAdd " style="float:left">添加</a>
									{/if}-->
									{$items.price_name}
								</div>
								</td>
								{if !$items.childs}
									{foreach item=item key=itemk from=$formula_table.basic_count_arr} 
											{if $itemk eq 0}
											<td>
												<div><input name="cell_price[{$items.id}][{$item}][]" value="{if $table_data.price_data[$items.id][$item][$first]}{$table_data.price_data[$items.id][$item][$first]}{/if}" size="7"></div>
											</td>
											{else}
											<td>
												<input name="cell_price[{$items.id}][{$item}][]" value="{$table_data.price_data[$items.id][$item][$first]}" size="7" class="number">
											</td>
											{/if}
									{/foreach}
								{/if}
							</tr>
								{foreach item=item key=ke from=$items.childs}
									<tr width="80%">
										<td rowspan="{$item.count}" colspan="1" class="fomula_table_{$key}_{$ke} formula_{$item.id}" depth="2" tdid="{$item.id}" arrcount="0">
										<div>
											<!--{if !$item.childs}
												<a href="javascript:void(0)" class="btnAdd " style="float:left">添加</a>
											{/if}-->
											{$item.price_name}
										</div>
										</td>
										{if !$item.childs}
											<td>
												<div>____</div>
											</td>
											{foreach item=item_ key=itemk from=$formula_table.basic_count_arr} 
												{if $itemk eq 0}
												<td>
													<div><input name="cell_price[{$item.id}][{$item_}][]" value="{if $table_data.price_data[$item.id][$item_][$itemk]}{$table_data.price_data[$item.id][$item_][$itemk]}{/if}" size="7" readonly></div>
												</td>
												{else}
												<td>
													<input name="cell_price[{$item.id}][{$item_}][]" value="{$table_data.price_data[$item.id][$item_][$itemk]}" size="7" class="number" {if $itemk eq 2}readonly{/if}>
												</td>
												{/if}
											{/foreach}
										{/if}
									</tr>
									{foreach item=ite key=k from=$item.childs}
										<tr width="80%">
											<td rowspan="{$ite.count}" colspan="1" class="fomula_table_{$key}_{$ke}_{$k} formula_{$ite.id}" depth="3" tdid="{$ite.id}" arrcount="0">
											<div>
												<!--{if !$ite.childs}
													<a href="javascript:void(0)" class="btnAdd " style="float:left">添加</a>
												{/if}-->
												{$ite.price_name}
											</div>
											</td>
											{foreach item=item key=itemk from=$formula_table.basic_count_arr} 
												{if $itemk eq 0}
												<td>
													<div><input name="cell_price[{$ite.id}][{$item}][]" value="{if $table_data.price_data[$ite.id][$item][$itemk]}{$table_data.price_data[$ite.id][$item][$itemk]}{/if}" size="7" readonly></div>
												</td>
												{else}
												<td>
													<input name="cell_price[{$ite.id}][{$item}][]" value="{$table_data.price_data[$ite.id][$item][$itemk]}" size="7" class="number" {if $itemk eq 2}readonly{/if}>
												</td>
												{/if}
											{/foreach}
										</tr>
										{foreach item=it key=k_ from=$ite.childs}
											<tr width="80%">
												<td rowspan="{$it.count}" colspan="1" class="fomula_table_{$key}_{$ke}_{$k}_{$k_}" depth="4" tdid="{$it.id}" arrcount="0">
													{$it.price_name}
												</td>
												{foreach item=item key=itemk from=$formula_table.basic_count_arr} 
												{if $itemk eq 0}
												<td>
													<div><input name="cell_price[{$it.id}][{$item}][]" value="{if $table_data.price_data[$it.id][$item][$first]}{$table_data.price_data[$it.id][$item][$first]}{/if}" size="7"></div>
												</td>
												{else}
												<td>
													<input name="cell_price[{$it.id}][{$item}][]" value="{$table_data.price_data[$it.id][$item][$first]}" size="7" class="number">
												</td>
												{/if}
												{/foreach}
											</tr>
										{/foreach}
									{/foreach}
								{/foreach}
							{/foreach}
							
							<!--{foreach item=items key=keys from=$formula_table.transport}								
									{foreach item=item key=key from=$items}
										<tr width="80%">
										{if $key eq 0}
											<td rowspan="<?php echo count($this->_var['items']);?>">
													<div>{$keys}</div>
											</td>
										{/if}
										<td>
											<div>{$item.province}</div>
										</td>
										<td>
											<div>{$item.city}</div>
										</td>
										<td>
											<div>{$item.area}</div>
										</td>
										<td>
											<div>{$item.street}</div>
										</td>
										{foreach item=item_ key=itemk from=$formula_table.basic_count_arr}
											{if $itemk eq 0}
											<td class="cell_cancel">
												<input name="transport_price[{$item.area_id}][{$item_}]" value="{if $table_data.transport_data[$item.area_id][$item_]}{$table_data.transport_data[$item.area_id][$item_]}{/if}" size="7">
											</td>
											{else}
											<td>
												<input name="transport_price[{$item.area_id}][{$item_}]" value="{$table_data.transport_data[$item.area_id][$item_]}" size="7">
											</td>
											{/if}
										{/foreach}
										</tr>
									{/foreach}
							{/foreach}-->
							
						</tbody>
					</table>
				</center>

		</div>
		
		<div class="formBar">
			<ul>
				<!--{if $table_data.price_data}
				<li><a class="add" href="/index.php?act=formula&st=modify_batch&id={$parent_id}" target="dialog" rel="modify_batch" title="批量修改数据" mask="true" width="830" height="400"><span>批量修改</span></a></li>
				{/if}-->
				<li><div class="buttonActive"><div class="buttonContent"><button type="submit">提交</button></div></div></li>
				<li><div class="button"><div class="buttonContent"><button type="button" class="close">取消</button></div></div></li>
			</ul>
		</div>

	</form>

</div>

<script type="text/javascript">
$(function(){
	//var formula_title = {$formula_table.basic_count_js};
	//var formula_price_data = {$table_data.price_data_js};
	//添加
	/*$(".formula a.btnAdd").die("click");
	$(".formula a.btnAdd").live("click",function(){
		var obj = $(this).parents("td");
		var tdid = obj.attr("tdid");
		//生成html代码
		var _html = "";
		for(var i = 1;i <= {$formula_table.basic_count_num}; i++){
			_html += '<td><input name="cell_price['+tdid+']['+formula_title[i]+'][]" value="" size="7"></td>';
		}
		_html = '<tr width="80%"><td  pid="'+obj.attr("class")+'" class="cell_cancel"><input name="cell_price['+tdid+']['+formula_title[0]+'][]" value="" size="7"><a href="javascript:void(0)" class="btnDel " style="float:right;">删除</a></td>' + _html + '</tr>';
		//自身高度加一
		var depth = obj.attr("depth");
		var objclass = obj.attr("class");
		var classarr = objclass.split(" ");
		objclass = classarr[0];
		var rowspan = parseInt($("." + objclass).attr("rowspan"),10);
		rowspan = isNaN(rowspan)?1:rowspan;
		rowspan += 1;
		$("." + objclass).attr("rowspan", rowspan);
		//父级元素高度加一
		for(var $i = depth; $i > 1; $i--){
			objclass = objclass.replace(/_[0-9]+$/,"");
			rowspan = parseInt($("." + objclass).attr("rowspan"), 10);
			rowspan = isNaN(rowspan)?1:rowspan;
			rowspan += 1;
			$("." + objclass).attr("rowspan", rowspan);
		}
		//添加一个元素
		obj.parents("tr").after(_html);
	});

	//删除
	$(".formula a.btnDel").die("click");
	$(".formula a.btnDel").live("click", function(){
		var obj = $(this).parents("td");
		//自身高度减一
		var objclass = obj.attr("pid");
		var classarr = objclass.split(" ");
		objclass = classarr[0];
		var depth = $("."+objclass).attr("depth");
		
		var rowspan = parseInt($("." + objclass).attr("rowspan"),10);
		rowspan = isNaN(rowspan)?1:rowspan;
		rowspan -= 1;
		$("." + objclass).attr("rowspan", rowspan);
		//父级元素高度减一
		for(var $i = depth; $i > 1; $i--){
			objclass = objclass.replace(/_[0-9]+$/,"");
			rowspan = parseInt($("." + objclass).attr("rowspan"), 10);
			rowspan = isNaN(rowspan)?1:rowspan;
			rowspan -= 1;
			$("." + objclass).attr("rowspan", rowspan);
		}
		//移除元素
		obj.parents("tr").remove();
	});*/
	//初始化保存的数据
	/*function init_data(){
		var obj = formula_price_data;
		$.each(obj,function(key, value){
			var len = value['range'].length;
			if(len >= 2){
				$.each(value['range'], function(k, v){
					if(k >= 1){
						$(".formula_" + key + " a.btnAdd").trigger("click");
						$.each(value , function($k, $v){
							$.each($v, function($k_, $v_){
								if($k_ >= 1){
									var target = "input[name='cell_price["+key+"]["+$k+"][]']:eq("+($k_)+")";alert(target);
									$(target).val($v_);
								}
							});
						});
					}
				});
			}
		});
		
	}
	init_data();*/
	//隐藏左边菜单
	/*setTimeout(function(){
		if($("#sidebar").is(":visible")){
			$("#sidebar .toggleCollapse div").trigger("click");
		}
	}, 10);*/
	$("input[readonly!=readonly]").bind("keyup", function(){
		var val = parseFloat($(this).val(),10);
		val = isNaN(val)?0:val;
		$(this).val(val);
		var pre = parseFloat($(this).parent().prev().children().children().val(), 10);
		$(this).parent().next().children().val(val-pre);
	});
});
</script>